package top.ljlgithub.api.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import top.ljlgithub.api.bean.Menu;
import top.ljlgithub.api.bean.Right;
import top.ljlgithub.api.bean.TreeBO;
import top.ljlgithub.api.common.response.Meta;
import top.ljlgithub.api.common.response.ResponseEntity;
import top.ljlgithub.api.mapper.RightMapper;
import top.ljlgithub.api.service.RightService;

import java.util.List;

/**
 * @ClassName
 * @Description TODO
 * @Author L1470
 * @Date 2021/5/6 7:21
 * @Version 1.0
 **/
@RestController
@CrossOrigin
public class RightController {
    @Autowired
    RightService rightService;

    @RequiresPermissions("user:getAllRights:*")
    @GetMapping("/rights/list")
    public ResponseEntity getRightList(){
        Meta meta = new Meta("获取权限列表成功", 200);
        List<Right> rightList = rightService.getRightList();
        ResponseEntity<Object> result = new ResponseEntity<>(rightList,meta);
        return result;
    }

    @RequiresPermissions("user:getAllRights:*")
    @GetMapping("/rights/tree")
    public ResponseEntity getRightTree(){
        Meta meta = new Meta("获取权限列表成功", 200);
        List<TreeBO> rightTree = rightService.selectNodeTreeByPid();
        ResponseEntity<Object> result = new ResponseEntity<>(rightTree,meta);
        return result;
    }


    @GetMapping("/menus")
    public ResponseEntity getMenuList(){
        Meta meta = new Meta("获取菜单列表成功", 200);
        List<Menu> menuTree = rightService.getMenuTree();
        ResponseEntity<Object> result = new ResponseEntity<>(menuTree,meta);
        return result;
    }
}
